n = 10;%% each block contains n trials;
s = 1;%% starting trial;
e = 10;%% ending trial;
block_name =1;%% the name of saved data;
%% %% find the min length;
 for i = s:e
    filename = sprintf('rec_signal/%d_rec_signal.csv',i);
    raw_data = importdata(filename);
    test_length(i) = length(raw_data);
 end
    m = min(test_length(s:e));%% min length;
    %% extract the data;
 for k =1:8 %% 8 muscle. 
 for j = s:e %% extract the k muscle's data.
    filename = sprintf('rec_signal/%d_rec_signal.csv',j);
    raw_data = importdata(filename);
    raw_data = raw_data(1:m,k);
    for l = 1:n
    sub_data(:,n) = raw_data(:);
    end
    a = mean(sub_data,2);
    all_data(:,k) = a;
 end
 end 
    save_filename = sprintf('block_average/%d_average_data',block_name);
    xlswrite(save_filename,all_data);
 


